package com.yaoxuguang.concurrence.reentrantlock.conditon;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.reentrantlock.conditon
 * @Description: 利用Conditon实现等待/通知
 * @date 2018年12月24日15:47
 */
public class UseConditionWaitNotifyError {
    private Lock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    public void waitMehtod(){
        try {
            lock.lock();
            System.out.println("a");
            condition.await();
            System.out.println("b");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
            System.out.println("c");
        }
    }

    public void signal(){
        try {
            lock.lock();
            System.out.println("aa");
            condition.signal();
            System.out.println("bb");
        } finally {
            lock.unlock();
            System.out.println("cc");
        }
    }
}
